package com.example.demo.reflect;

import java.lang.reflect.Constructor;

class Parent {
    public Parent() {}
    protected Parent(String name) {}
    private Parent(int age) {}
}

class Child extends Parent {
    public Child() {}
    protected Child(String name) {}
    private Child(int age) {}
}

public class ReflectionExample {
    public static void main(String[] args) {
        // 获取Child类的Class对象
        Class<?> clazz = Child.class;

        // 获取Child类中声明的所有构造方法（不包括父类）
        System.out.println("Declared Constructors of Child:");
        Constructor<?>[] declaredConstructors = clazz.getDeclaredConstructors();
        for (Constructor<?> constructor : declaredConstructors) {
            System.out.println(constructor);
        }

        // 获取Child类中所有的public构造方法（包括从父类继承的）
        System.out.println("\nPublic Constructors of Child (including inherited):");
        Constructor<?>[] publicConstructors = clazz.getConstructors();
        for (Constructor<?> constructor : publicConstructors) {
            System.out.println(constructor);
        }
    }
}